﻿using System.Net;

namespace Ndns.Net
{
    public static class DnsServerBuilderExtensions
    {

        public static ICompositeDnsServerBuilder SetHandler<TDnsRequestHandler>(this ICompositeDnsServerBuilder builder) where TDnsRequestHandler : IDnsRequestHandler, new()
        {
            return builder.SetHandler(new TDnsRequestHandler());
        }

        public static ICompositeDnsServerBuilder Add(this ICompositeDnsServerBuilder builder, IDnsServer server, object tag)
        {
            builder.Add(server);
            server.Tag = tag;
            return builder;
        }

        public static ICompositeDnsServerBuilder AddUdpServer(this ICompositeDnsServerBuilder builder, IPEndPoint localEP)
        {
            return builder.Add(new DnsUdpServer(localEP));
        }

        public static ICompositeDnsServerBuilder AddUdpServer(this ICompositeDnsServerBuilder builder, IPEndPoint localEP, object tag)
        {
            return builder.Add(new DnsUdpServer(localEP) { Tag = tag });
        }

        public static ICompositeDnsServerBuilder AddTcpServer(this ICompositeDnsServerBuilder builder, IPEndPoint localEP)
        {
            return builder.Add(new DnsTcpServer(localEP));
        }

        public static ICompositeDnsServerBuilder AddTcpServer(this ICompositeDnsServerBuilder builder, IPEndPoint localEP, object tag)
        {
            return builder.Add(new DnsTcpServer(localEP) { Tag = tag });
        }
    }
}
